/**
 * @首页相关js
 * @author yanlingling
 */

window.onload = function() {
	index.init();
}
var index = {

	/**
	 *起始处
	 */
	init : function() {
	   var me = this;
	   common.navInit(0);
		
		//绑定语言切换
	   common.switchLanInit();
		
	   common.sendRequest(BANNER_INFO_PATH, {}, me.getBannerCallback);
		//获取banner图片信息

		var noticeParam = '{"indexId":0,"num":4}';
		common.sendRequest(NOTICE_INFO_PATH, noticeParam, me.getNoticeCallback);

		/*获取如何使用链接信息*/
		var howToUseParam ='{"indexId":0,"num":4}';
		common.sendRequest(HOW_TO_USE, howToUseParam, me.getHowToUseCallback);

		/*成功案例信息*/
		var sucessCaseParam = '{"indexId":0,"num":4}';
		common.sendRequest(SUCCESS_CASE_PATH, sucessCaseParam, me.getSucessCaseCallback);
      
	},

	/**
	 *获取banner信息的回调
	 * @param {Object} data
	 */
	getBannerCallback : function(data) {
	   var color = [];
		for(var i = 0; i < data.length; i++) {
			color.push(data[i].backgroundColor);
		};
		$("#banner").vpic({
			color : color,
			width : 960,
			height : 400,
			imgSource : data
		});

	},

	/**
	 *获取通知信息的回调
	 * @param {Object} data
	 */
	getNoticeCallback : function(data) {
	    var notice = data;
		var noticeDom = $('#moreNotice');
		var me = this;
		for(var i = 0; i < data.length; i++) {
			if(data[i].top && data[i].top == true) {
				$('#advImg').attr('src', data[i].img);
				$('#advLink').attr("href",data[i].href)
				$('#advTitle').html(data[i].title);
				var detail = common.sendTextRequest(data[i].detail);
				//请求消息内容
				$('#advContent').html(getCutString(detail,50,'......')+'<a href="'+data[i].href+'">&nbsp;&nbsp;['+detailConfig+']</a>');
			} else {
				var time = data[i].time;
				var fomatDate = common.getLocalTime(time);
				//console.log(fomatDate);
				//new Date(parseInt(data[i].time) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
				var htmlStr = "<div class='content'><span class='smallDot'></span><a  href='"+data[i].href+"' class='noticeTitle'>" + getCutString(data[i].title,50,'') + "</a><span class='noticeDate'>" + fomatDate + "</span></div>"
				$('#moreNotice').append(htmlStr)
			}
		};

	},

	/**
	 *如何使用callback
	 * @param {Object} data
	 */
	getHowToUseCallback : function(data) {
 		for(var i = 0; i < data.length && i < 3; i++) {
			var stepData = data[i];
			$('#htu-step' + (i + 1) + '-title').html(stepData.title);
			var htmlStr = [];
			for(var j = 0; j < stepData.subTitles.length && j < 4; j++) {
				var subData = stepData.subTitles;

				htmlStr[htmlStr.length] = "<div><span class='smallDot'></span><a href='" + subData[j].href + "'>" + getCutString(subData[j].title,20,'...') + "</a></div>"

			} ;
			$('#htu-step' + (i + 1)).html(htmlStr.join(''));
		};

	},

	/**
	 *成功案例的回调处理
	 * @param {Object} data
	 */
	getSucessCaseCallback : function(data) {
	   var htmlStr = [];
	   
		for(var i = 0; i < data.length && i < 5; i++) {

			htmlStr[htmlStr.length] = "<div class='sucCaseBlock'>"
			htmlStr[htmlStr.length] = "<a class='sucessCaseImgLink' href='"+data[i].href+"'><img width=60 height=60 src=" + data[i].img + "></a>"
			htmlStr[htmlStr.length] = "<div class='sucCaseContent'>"
			htmlStr[htmlStr.length] = "<p class='caseName'>" + data[i].title + "</p>"
			htmlStr[htmlStr.length] = "<p >" + getCutString(data[i].detail,26,'......') + "<a href='"+data[i].href+"'>&nbsp;&nbsp;["+detailConfig+"]</a></p>"
			htmlStr[htmlStr.length] = "</div>"
			htmlStr[htmlStr.length] = "</div>"
		};
       $('#successCase').html(htmlStr.join(''));
	}
}